﻿import mx.utils.Delegate;

/**
 * ...
 * @author wangjun
 */
class cn.eminia.A2.preLoader.LoadAsBitmap {
	// [置顶]
	/*
	var loader= new AS2.ldClass.LoadAsBitmap(ctnr,{scope:this,stt:function(evt){
	  trace(evt.mc);
	 },pro:function(evt){
	    trace(evt.per);  
	   trace(evt.cur);  
	  trace(evt.ttl);   
	 },ok:function(evt){
	    trace(evt.mc);  
	 }});
	  loader.load('swf1.jpg');
	*/
	var mc:MovieClip;
	var ld:MovieClipLoader;
	var url,id;
	function LoadAsBitmap(scope, obj:Object) {
		/*
		if (mc == undefined || mc.constructor != MovieClip) {
		throw ('!!! Ld :: 无容器');
		}*/
		var dd = _root.getNextHighestDepth();
		this.mc = _root.createEmptyMovieClip('LoadAsBitmap_'+dd, dd);
		//
		this.ld = new MovieClipLoader();
		//
		var lis:Object = new Object();
		lis.onLoadStart = function(mc:MovieClip) {
			Delegate.create(scope, obj.stt)({mc:mc,id:id});
		};
		lis.onLoadProgress = Delegate.create(this,function(mc:MovieClip, ld:Number, tt:Number) {
			Delegate.create(scope, obj.pro)({per:Math.round(ld/tt*100), cur:ld, max:tt, mc:mc,url:url});
		});
		lis.onLoadInit = Delegate.create(this, function (mc:MovieClip) {
			var bm = new flash.display.BitmapData(mc._width, mc._height, true, 16777215);
			bm.draw(mc);
			//mc._visible = false;
			removeMovieClip(mc)
			mc=null
			//trace('mc :: '+mc)
			Delegate.create(scope, obj.ok)({bm:bm,url:url,id:id});
		});
		this.ld.addListener(lis);
	}
	function load(url):Void {
		//trace('url -> '+url+' ctt -> '+this.mc);
		this.url=url
		if(String(arguments[1])!='undefined')this.id=arguments[1]
		this.ld.loadClip(url, this.mc);
	}
}
